home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / uhren & terminkalender / time / sunclock / source / main.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  19KB  |  711 lines

  1. /*-------------------------------------------------------------------------
  2.     SunClock
  3.  
  4.     Amiga version by Mark Waggoner, 
  5.     waggoner@ichips.intel.com or wagnell@PDaXcess.techbook.com
  6.     December 1991
  7.  
  8.     This program was developed using Aztec C V5.0a and V5.2
  9.  
  10.     This program was derived from the X11 Sun clock program, which was
  11.     in turn derived from a suntools Sun clock program.  The author's notices
  12.     for those programs appear below.
  13.  
  14.     Since the previous versions of the program were made public domain,
  15.     I am also making this program public domain.  Sorry, no clever quote
  16.     from me.
  17.  
  18.     main.c
  19. -------------------------------------------------------------------------*/
  20. /*
  21.  * Sun clock.  X11 version by John Mackin.
  22.  *
  23.  * This program was derived from, and is still in part identical with, the
  24.  * Suntools Sun clock program whose author's comment appears immediately
  25.  * below.  Please preserve both notices.
  26.  *
  27.  * The X11R3/4 version of this program was written by John Mackin, at the
  28.  * Basser Department of Computer Science, University of Sydney, Sydney,
  29.  * New South Wales, Australia; <john@cs.su.oz.AU>.  This program, like
  30.  * the one it was derived from, is in the public domain: `Love is the
  31.  * law, love under will.'
  32.  */
  33.  
  34. /*
  35.     Sun clock
  36.  
  37.     Designed and implemented by John Walker in November of 1988.
  38.  
  39.     Version for the Sun Workstation.
  40.  
  41.     The algorithm used to calculate the position of the Sun is given in
  42.     Chapter 18 of:
  43.  
  44.     "Astronomical  Formulae for Calculators" by Jean Meeus, Third Edition,
  45.     Richmond: Willmann-Bell, 1985.  This book can be obtained from:
  46.  
  47.        Willmann-Bell
  48.        P.O. Box 35025
  49.        Richmond, VA  23235
  50.        USA
  51.        Phone: (804) 320-7016
  52.  
  53.     This program was written by:
  54.  
  55.        John Walker
  56.        Autodesk, Inc.
  57.        2320 Marinship Way
  58.        Sausalito, CA  94965
  59.        USA
  60.        Fax:   (415) 389-9418
  61.        Voice: (415) 332-2344 Ext. 2829
  62.        Usenet: {sun,well,uunet}!acad!kelvin
  63.        or: kelvin@acad.uu.net
  64.  
  65.     This  program is in the public domain: "Do what thou wilt shall be the
  66.     whole of the law".  I'd appreciate  receiving  any  bug  fixes  and/or
  67.     enhancements,  which  I'll  incorporate  in  future  versions  of  the
  68.     program.  Please leave the original attribution information intact    so
  69.     that credit and blame may be properly apportioned.
  70.  
  71.     Revision history:
  72.  
  73.     1.0  12/21/89  Initial version.
  74.           8/24/89  Finally got around to submitting.
  75.  
  76. */
  77. #include <stdio.h>
  78. #include <stdlib.h>
  79. #include <functions.h>
  80. #include <string.h>
  81. #include <intuition/intuition.h>
  82. #include <graphics/gfx.h>
  83.  
  84. #include "images.h"
  85.  
  86. extern void UpdateImages(int force);
  87. extern int    OpenTimer(ULONG sec,ULONG micro);
  88. extern void CloseTimer(void);
  89. extern void ResetTimeReq(ULONG sec,ULONG micro);
  90. extern void AbortTimer(void);
  91.  
  92. /*-------------------------------------------------------------------------
  93.     Gobs of global data 
  94. -------------------------------------------------------------------------*/
  95. struct Library            *IntuitionBase = NULL;
  96. struct Library            *GfxBase = NULL;
  97.  
  98. /*--- Information about the About window ---*/
  99. struct Window    *AboutWin = NULL;
  100. ULONG    AboutMask = 0;
  101.  
  102. /*--- Information about the "icon" window on the workbench ---*/
  103. int                AdjustIcon = 1;        /* Flag */
  104. int                FullScreen = 0;        /* Flag */
  105. int                AdjustedIconHeight,AdjustedIconWidth;
  106. int                IconTop,IconLeft;
  107. static WORD        IconIllum[IconHeight];
  108. struct Window    *IconWin = NULL;
  109. int                whitepen,blackpen;
  110. struct NewWindow NewIconWindow = {
  111.         0,0,10,10,            /* x,y,w,h                  */
  112.         -1,-1,              /* gadget pen,border pen    */
  113.         CLOSEWINDOW|MOUSEBUTTONS|REFRESHWINDOW|MENUPICK,
  114.                             /* IDCMP Flags              */
  115.         WINDOWDEPTH|WINDOWCLOSE|WINDOWDRAG|SIMPLE_REFRESH,
  116.                             /* System Flags             */
  117.         NULL,NULL,            /* Gadget and Check Image   */
  118.         (UBYTE *)"Sunclock",/* Title                    */
  119.         NULL,               /* Screen to put it in (if TYPE is custom) */
  120.         NULL,               /* Pointer to Bitmap for SUPER BIT MAP windows */
  121.         -1, -1,                /* minimum width,height     */
  122.         -1, -1,                /* maximum width,height     */
  123.         WBENCHSCREEN        /* screen TYPE              */
  124. };
  125.  
  126.  
  127. /*--- Information about the main window on its own screen ---*/
  128. int                AdjustedMainHeight,AdjustedMainWidth;
  129. int                MainTop,MainLeft;
  130. static WORD        MainIllum[MainHeight];
  131. struct Screen    *MainScreen = NULL;
  132. struct Window    *MainWin = NULL;
  133. char            loctimestr[50];
  134. char            gmtimestr[50];
  135. struct NewScreen NewMainScreen = {
  136.         0,0,640,STDSCREENHEIGHT,1,0,1,
  137.         HIRES|LACE,
  138.         CUSTOMSCREEN,NULL,(UBYTE *) "Sunclock",
  139.         NULL,NULL
  140. };
  141.  
  142. struct NewWindow NewMainWindow = {
  143.         0,0,10,10,            /* x,y,w,h                  */
  144.         -1,-1,              /* gadget pen,border pen    */
  145.         MOUSEBUTTONS|REFRESHWINDOW|MENUPICK,
  146.                             /* IDCMP Flags              */
  147.         BORDERLESS|BACKDROP|SIMPLE_REFRESH,
  148.                             /* System Flags             */
  149.         NULL,NULL,            /* Gadget and Check Image   */
  150.         NULL,                /* Title                    */
  151.         NULL,               /* Screen to put it in (if TYPE is custom) */
  152.         NULL,               /* Pointer to Bitmap for SUPER BIT MAP windows */
  153.         -1, -1,                /* minimum width,height     */
  154.         -1, -1,                /* maximum width,height     */
  155.         CUSTOMSCREEN        /* screen TYPE              */
  156. };
  157.  
  158. /*--- These are set according to whether the window is in its ---*/
  159. /*--- iconized form or its full form. ---*/
  160. struct    Window        *Win;
  161. struct    MsgPort        *SigPort;
  162. ULONG    WinMask;
  163. UWORD    *Data;
  164. WORD    *Illum;
  165. UWORD    DataWidth,DataHeight;
  166. void    (*MapRefresh)(void);
  167. void    (*TextRefresh)(void);
  168. struct    BitMap    MapBitMap;
  169. struct    BitMap    IllumBitMap;
  170.  
  171. /*--- Used to get a copy of the workbench screen information ---*/
  172. struct Screen    WBScreen;
  173.  
  174. /*--- Timer data ---*/
  175. struct    MsgPort            *Timer_Port = NULL;
  176. struct    timerequest        Time_Request;
  177. ULONG                    TimerMask = 0;
  178. ULONG                    DelaySec,DelayMicro;
  179.  
  180. /*--- TimerMask | WinMask ---*/
  181. ULONG    SigMask;
  182.  
  183. /*--- Menu data ---*/
  184. extern struct Menu ProjectMenu;
  185. extern struct MenuItem ProjectItems[];
  186.  
  187. /*--- Text for the about window ---*/
  188. char *AllAboutMe[] = {
  189. "SunClock, Amiga version 1.0 by Mark Waggoner, derived from:",
  190. "          X11 version by John Mackin, derived from:",
  191. "          Suntools version by John Walker.",
  192. "Double click on the world image or use the Iconize menu to switch",
  193. "between the workbench window and a full screen image.",
  194. "",
  195. "To get a correct display of the illuminated portion of the globe,",
  196. "set the environment variable TZ to ZZZnDDD",
  197. "where ZZZ = Time zone name.",
  198. "      n   = Number of hours you are away from GMT.",
  199. "      DDD = Time zone name during daylight savings time.",
  200. "For example, setenv TZ=PST8PDT for pacific time",
  201. "",
  202. "Tooltypes and options:",
  203. "LEFT=x   TOP=y   FULLSCREEN   DONOTADJUST",
  204. "See the documentation for more information",
  205. NULL
  206. };
  207.  
  208. /*-------------------------------------------------------------------------
  209.     Open and close the libraries we need
  210. -------------------------------------------------------------------------*/
  211. void
  212. OpenLibs(void) {
  213.     if (!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library",0L))) {
  214.         exit(100);
  215.     }
  216.     if (!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",0L))) {
  217.         CloseLibrary(IntuitionBase);
  218.         exit(100);
  219.     }
  220. }
  221.  
  222. void
  223. CloseLibs(void) {
  224.     if (GfxBase) CloseLibrary(GfxBase);
  225.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  226. }
  227.  
  228. /*-------------------------------------------------------------------------
  229.     Get info about the workbench screen and adapt to it
  230. -------------------------------------------------------------------------*/
  231. void
  232. AdjustToScreen(void)
  233. {
  234.     int i,pen,minpen=15*3,maxpen=0;
  235.     ULONG RGB;
  236.  
  237.     GetScreenData((char *)&WBScreen,sizeof(WBScreen),WBENCHSCREEN,NULL);
  238.  
  239.     /* Figure out how wide to make the window */
  240.     NewIconWindow.Width = IconWidth + 
  241.                             WBScreen.WBorLeft + WBScreen.WBorRight;
  242.  
  243.     /* If operating on a non-interlaced screen, use alternate lines of the
  244.        icon image */
  245.     AdjustedIconWidth  = IconWidth;
  246.     AdjustedIconHeight = IconHeight;
  247.     AdjustedMainWidth  = MainWidth;
  248.     AdjustedMainHeight = MainHeight;
  249.  
  250.     if (!(WBScreen.ViewPort.Modes & LACE) && AdjustIcon) {
  251.         AdjustedIconWidth  *= 2;
  252.         AdjustedIconHeight /= 2;
  253.         AdjustedMainWidth  *= 2;
  254.         AdjustedMainHeight /= 2;
  255.     }
  256.  
  257.     NewIconWindow.Height = AdjustedIconHeight + WBScreen.BarHeight +
  258.                             WBScreen.WBorTop + WBScreen.WBorBottom;
  259.  
  260.     /* The position of the bitmap within the window */
  261.     IconTop  = WBScreen.BarHeight + WBScreen.WBorTop;
  262.     IconLeft = WBScreen.WBorLeft;
  263.  
  264.     /* Now figure out which pens are "whitest" and "blackest" */
  265.     whitepen = 1;
  266.     blackpen = 0;
  267.  
  268.     for(i = 0;i < 1<<WBScreen.BitMap.Depth; i++) {
  269.         RGB = GetRGB4(WBScreen.ViewPort.ColorMap,i);
  270.  
  271.         pen = (RGB & 0x00f) + ((RGB & 0x0f0) >> 4) + ((RGB & 0xf00) >> 8);
  272.         if (pen < minpen) {
  273.             minpen = pen;
  274.             blackpen = i;
  275.         }
  276.         if (pen > maxpen) {
  277.             maxpen = pen;
  278.             whitepen = i;
  279.         }
  280.     }
  281. }
  282.  
  283. /*-------------------------------------------------------------------------
  284.     Draw the main image
  285. -------------------------------------------------------------------------*/
  286. void
  287. TextMain(void)
  288. {
  289.     int sl,l;
  290.  
  291.     SetAPen(MainWin->RPort,1);
  292.     SetBPen(MainWin->RPort,0);
  293.     SetDrMd(MainWin->RPort,JAM2);
  294.  
  295.     l = TextLength(MainWin->RPort,loctimestr,sl = strlen(loctimestr));
  296.     Move(MainWin->RPort,(MainWidth+MainLeft-l)/2,
  297.         MainTop+MainHeight+MainWin->RPort->Font->tf_YSize+1);
  298.     Text(MainWin->RPort,loctimestr,sl);
  299.     l = TextLength(MainWin->RPort,gmtimestr,sl = strlen(gmtimestr));
  300.     Move(MainWin->RPort,(MainWidth+MainLeft-l)/2,
  301.         MainTop+MainHeight+2*MainWin->RPort->Font->tf_YSize+2);
  302.     Text(MainWin->RPort,gmtimestr,sl);
  303. }
  304. void
  305. DrawMain(void) 
  306. {
  307.     SetAPen(MainWin->RPort,0);
  308.     SetBPen(MainWin->RPort,1);
  309.     SetDrMd(MainWin->RPort,JAM2);
  310.  
  311.     BltTemplate((PLANEPTR)IllumBitMap.Planes[0],0,((MainWidth+15)/16)*2,
  312.                 MainWin->RPort,
  313.                 MainLeft,MainTop,MainWidth,MainHeight);
  314.  
  315. }
  316.  
  317. /*-------------------------------------------------------------------------
  318.     Start the main window (full sized map)
  319. -------------------------------------------------------------------------*/
  320. int
  321. StartMainWindow(void)
  322. {
  323.     /* Get rid of the raster used for the icon map */
  324.     if (IllumBitMap.Planes[0])
  325.         FreeRaster(IllumBitMap.Planes[0],DataWidth,DataHeight);
  326.  
  327.     /* Open our own screen */
  328.     NewMainScreen.Width = MainWidth;
  329.  
  330.     if (!(MainScreen = OpenScreen(&NewMainScreen))) return 0;
  331.  
  332.     /* Set colors for black and white */
  333.     SetRGB4(&MainScreen->ViewPort,0, 0, 0, 0); /* Outline */
  334.     SetRGB4(&MainScreen->ViewPort,1,15,15,15); /* Background */
  335.  
  336.     /* Open our window */
  337.     NewMainWindow.Width = MainWidth;
  338.     NewMainWindow.Height = MainScreen->Height - MainScreen->BarHeight;
  339.     NewMainWindow.Screen = MainScreen;
  340.     NewMainWindow.TopEdge = MainScreen->BarHeight;
  341.  
  342.     MainTop = 0;
  343.     MainLeft = 0;
  344.  
  345.     if (!(MainWin = OpenWindow(&NewMainWindow))) {
  346.         CloseScreen(MainScreen);
  347.         return 0;
  348.     }
  349.  
  350.     /* Set up global pointers to the window, etc */
  351.     Win = MainWin;
  352.     SigPort = Win->UserPort;
  353.     WinMask = 1L<<SigPort->mp_SigBit;
  354.     SigMask = WinMask | TimerMask | AboutMask;
  355.     MapRefresh = DrawMain;
  356.     TextRefresh = TextMain;
  357.     DataWidth = MainWidth;
  358.     DataHeight = MainHeight;
  359.     Data = MainData;
  360.     Illum = MainIllum;
  361.  
  362.     /* Set up the bitmap structure for the full sized map */
  363.     InitBitMap(&MapBitMap,2,MainWidth,MainHeight);
  364.     MapBitMap.Planes[0] = (PLANEPTR) MainData;
  365.     /* Allocate and set up a bitmap for the illumination mask */
  366.     InitBitMap(&IllumBitMap,1,MainWidth,MainHeight);
  367.     if (!(IllumBitMap.Planes[0] = AllocRaster(MainWidth,MainHeight))) {
  368.         CloseWindow(MainWin);
  369.         CloseScreen(MainScreen);
  370.         return 0;
  371.     }
  372.  
  373.     ProjectItems[1].Flags &= ~CHECKED;
  374.     SetMenuStrip(MainWin,&ProjectMenu);
  375.  
  376.     DelaySec = 1;
  377.     DelayMicro = 0;
  378.     AbortTimer();
  379.  
  380.     UpdateImages(1);
  381.  
  382.     return 1;
  383. }
  384.  
  385. /*-------------------------------------------------------------------------
  386.     Switch to the Main Window
  387. -------------------------------------------------------------------------*/
  388. int
  389. SwitchToMain(void)
  390. {
  391.     if (MainWin) 
  392.         return 0;
  393.     if (IconWin) {
  394.         NewIconWindow.LeftEdge = IconWin->LeftEdge;
  395.         NewIconWindow.TopEdge = IconWin->TopEdge;
  396.         ClearMenuStrip(IconWin);
  397.         CloseWindow(IconWin);
  398.         IconWin = NULL;
  399.     }
  400.     if (!StartMainWindow()) return 1;
  401.     (*MapRefresh)();
  402.     (*TextRefresh)();
  403.     return 0;
  404. }
  405.  
  406. /*-------------------------------------------------------------------------
  407.     Start and End the About Window
  408. -------------------------------------------------------------------------*/
  409. void
  410. StartAbout(void)
  411. {
  412.     char *s;
  413.     int i;
  414.     struct NewWindow NW;
  415.  
  416.     if (AboutWin) return;
  417.  
  418.     NW.TopEdge = 
  419.     NW.LeftEdge = 0;
  420.     NW.Width = 600;
  421.     NW.Height = 200;
  422.     NW.DetailPen = NW.BlockPen = -1;
  423.     NW.IDCMPFlags = CLOSEWINDOW;
  424.     NW.Flags = WINDOWDEPTH|WINDOWSIZING|WINDOWCLOSE|WINDOWDRAG|
  425.                 SMART_REFRESH|NOCAREREFRESH;
  426.     NW.FirstGadget = NULL;
  427.     NW.CheckMark = NULL;
  428.     NW.Title = (UBYTE *) "About SunClock";
  429.     NW.Screen = NULL;
  430.     NW.BitMap = NULL;
  431.     NW.MinWidth = NW.MinHeight = 
  432.     NW.MaxWidth = NW.MaxHeight = -1;
  433.     NW.Type = WBENCHSCREEN;
  434.  
  435.     if (!(AboutWin = OpenWindow(&NW)))
  436.         return;
  437.  
  438.     SetAPen(AboutWin->RPort,whitepen);
  439.     SetDrMd(AboutWin->RPort,JAM1);
  440.     RectFill(AboutWin->RPort,AboutWin->BorderLeft,AboutWin->BorderTop,
  441.             AboutWin->Width-AboutWin->BorderLeft-AboutWin->BorderRight,
  442.             AboutWin->Height-AboutWin->BorderTop-AboutWin->BorderBottom);
  443.     
  444.     SetAPen(AboutWin->RPort,blackpen);
  445.  
  446.     for(i=0;AllAboutMe[i];i++) {
  447.         Move(AboutWin->RPort,10,
  448.             AboutWin->BorderTop+(i+1)*AboutWin->RPort->Font->tf_YSize+5);
  449.         Text(AboutWin->RPort,AllAboutMe[i],strlen(AllAboutMe[i]));
  450.  
  451.     }
  452.  
  453.     AboutMask = 1L<<AboutWin->UserPort->mp_SigBit;
  454.     SigMask = WinMask | TimerMask | AboutMask;
  455.  
  456.     WBenchToFront();
  457.  
  458.     return;
  459. }
  460. void
  461. EndAbout(void)
  462. {
  463.     if (AboutWin)
  464.         CloseWindow(AboutWin);
  465.     AboutWin = NULL;
  466.     AboutMask = 0;
  467.     SigMask = WinMask | TimerMask | AboutMask;
  468.     if (MainScreen)
  469.         ScreenToFront(MainScreen);
  470.     return;
  471. }
  472.  
  473. /*-------------------------------------------------------------------------
  474.     Draw the iconized image
  475. -------------------------------------------------------------------------*/
  476. void
  477. TextIcon(void)
  478. {
  479. }
  480. void
  481. DrawIcon(void)
  482. {
  483.  
  484.     SetAPen(IconWin->RPort,blackpen);
  485.     SetBPen(IconWin->RPort,whitepen);
  486.     SetDrMd(IconWin->RPort,JAM2);
  487.  
  488.     BltTemplate((PLANEPTR)IllumBitMap.Planes[0],0,((AdjustedIconWidth+15)/16)*2,
  489.                 IconWin->RPort,
  490.                 IconLeft,IconTop,IconWidth,AdjustedIconHeight);
  491. }
  492.  
  493. /*-------------------------------------------------------------------------
  494.     Start the icon window
  495. -------------------------------------------------------------------------*/
  496. int
  497. StartIconWindow(void)
  498. {
  499.     if (IllumBitMap.Planes[0])
  500.         FreeRaster(IllumBitMap.Planes[0],DataWidth,DataHeight);
  501.  
  502.     if (!(IconWin = OpenWindow(&NewIconWindow)))
  503.         return 0;
  504.     
  505.     Win = IconWin;
  506.     SigPort = Win->UserPort;
  507.     WinMask = 1L<<SigPort->mp_SigBit;
  508.     SigMask = WinMask | TimerMask | AboutMask;
  509.     MapRefresh = DrawIcon;
  510.     TextRefresh = TextIcon;
  511.     Data = IconData;
  512.     DataWidth = IconWidth;
  513.     DataHeight = IconHeight;
  514.     Illum = IconIllum;
  515.  
  516.     InitBitMap(&MapBitMap,1,IconWidth,IconHeight);
  517.     MapBitMap.Planes[0] = (PLANEPTR) IconData;
  518.     InitBitMap(&IllumBitMap,1,IconWidth,IconHeight);
  519.     if (!(IllumBitMap.Planes[0] = AllocRaster(IconWidth,IconHeight))) {
  520.         CloseWindow(IconWin);
  521.         return 0;
  522.     }
  523.  
  524.     ProjectItems[1].Flags |= CHECKED;
  525.     SetMenuStrip(IconWin,&ProjectMenu);
  526.  
  527.     DelaySec = 60;
  528.     DelayMicro = 0;
  529.     AbortTimer();
  530.  
  531.     UpdateImages(1);
  532.  
  533.     return 1;
  534. }
  535.  
  536. /*-------------------------------------------------------------------------
  537.     Switch to the Icon Window
  538. -------------------------------------------------------------------------*/
  539. int
  540. SwitchToIcon(void)
  541. {
  542.     if (IconWin) 
  543.         return 0;
  544.     if (MainWin) {
  545.         ClearMenuStrip(MainWin);
  546.         CloseWindow(MainWin);
  547.     }
  548.     if (MainScreen) CloseScreen(MainScreen);
  549.     MainWin = NULL;
  550.     MainScreen = NULL;
  551.     if (!StartIconWindow()) return 1;
  552.     (*MapRefresh)();
  553.     (*TextRefresh)();
  554.     return 0;
  555. }
  556.  
  557. /*-------------------------------------------------------------------------
  558.     Handle all events from the windows
  559. -------------------------------------------------------------------------*/
  560. int
  561. HandleWindowMsgs(void)
  562. {
  563.     struct    IntuiMessage *M;
  564.     struct    Window    *win;
  565.     struct    MenuItem    *item;
  566.     ULONG    sec,mic;
  567.     static    ULONG    sec0 = 0,mic0 = 0;
  568.     ULONG    class;
  569.     USHORT    code;
  570.  
  571.     while(M = (struct IntuiMessage *) GetMsg(SigPort)) {
  572.         class = M->Class;
  573.         code =  M->Code;
  574.         sec = M->Seconds;
  575.         mic = M->Micros;
  576.         win = M->IDCMPWindow;
  577.  
  578.         ReplyMsg((struct Message *) M);
  579.  
  580.         switch(class) {
  581.             case CLOSEWINDOW:
  582.                 return 1;
  583.                 break;
  584.             case REFRESHWINDOW:
  585.                 BeginRefresh(Win);
  586.                 (*MapRefresh)();
  587.                 (*TextRefresh)();
  588.                 EndRefresh(Win,1);
  589.                 break;
  590.             case MOUSEBUTTONS:
  591.                 if (code == SELECTDOWN) {
  592.                     if (DoubleClick(sec0,mic0,sec,mic)) {
  593.                         if (IconWin) {
  594.                             if (SwitchToMain()) return 1;
  595.                         }
  596.                         else {
  597.                             if (SwitchToIcon()) return 1;
  598.                         }
  599.                     }
  600.                     sec0 = sec;
  601.                     mic0 = mic;
  602.                 }
  603.                 break;
  604.             case MENUPICK:
  605.                 while (code != MENUNULL) {
  606.                     item = ItemAddress(&ProjectMenu,code);
  607.                     switch(ITEMNUM(code)) {
  608.                         case 0:    /* About */
  609.                             StartAbout();
  610.                             break;
  611.                         case 1: /* Iconize */
  612.                             if (item->Flags & CHECKED) {
  613.                                 if (SwitchToIcon()) return 1;
  614.                             }
  615.                             else {
  616.                                 if (SwitchToMain()) return 1;
  617.                             }
  618.                             break;
  619.                         case 2: /* Quit */
  620.                             return 1;
  621.                             break;
  622.                         default:
  623.                             break;
  624.                     }
  625.                     code = item->NextSelect;
  626.                 }
  627.                 break;
  628.             default:
  629.                 break;
  630.         }
  631.     }
  632.     return 0;
  633. }
  634.  
  635. /*-------------------------------------------------------------------------
  636.     The main Event loop
  637. -------------------------------------------------------------------------*/
  638. void
  639. MainLoop(void) 
  640. {
  641.     ULONG    MsgMask;
  642.  
  643.     if (FullScreen) {
  644.         if (!StartMainWindow()) return;
  645.     }
  646.     else {
  647.         if (!StartIconWindow()) return;
  648.     }
  649.     (*MapRefresh)();
  650.     (*TextRefresh)();
  651.  
  652.  
  653.     while (1) {
  654.         MsgMask = Wait(SigMask);
  655.  
  656.         if (MsgMask & TimerMask) {
  657.             UpdateImages(0);
  658.             ResetTimeReq(DelaySec,DelayMicro);
  659.         }
  660.  
  661.         if (MsgMask & WinMask) {
  662.             if (HandleWindowMsgs()) return;
  663.         }
  664.  
  665.         if (MsgMask & AboutMask) {
  666.             EndAbout();
  667.         }
  668.     }
  669. }
  670.  
  671. /*-------------------------------------------------------------------------
  672.     Clean up all of our resources 
  673. -------------------------------------------------------------------------*/
  674. void
  675. clean_up(void) {
  676.     if (AboutWin)
  677.         CloseWindow(AboutWin);
  678.     CloseTimer();
  679.     if (IllumBitMap.Planes[0])
  680.         FreeRaster(IllumBitMap.Planes[0],DataWidth,DataHeight);
  681.     if (IconWin) {
  682.         ClearMenuStrip(IconWin);
  683.         CloseWindow(IconWin);
  684.     }
  685.     if (MainWin) {
  686.         ClearMenuStrip(MainWin);
  687.         CloseWindow(MainWin);
  688.     }
  689.     if (MainScreen) CloseScreen(MainScreen);
  690.     CloseLibs();
  691. }
  692.  
  693. main(int argc,char *argv[])
  694. {
  695.     /* Add the cleanup routine to the actions to take at exit time */
  696.     if (atexit(clean_up))
  697.         exit(20);
  698.  
  699.     OpenLibs();
  700.  
  701.     DelaySec = 5;
  702.     DelayMicro = 0;
  703.     if (!OpenTimer(DelaySec,DelayMicro)) exit(20);
  704.  
  705.     AdjustToScreen();
  706.  
  707.     MainLoop();
  708.  
  709.     exit(0);
  710. }
  711.